<?php

/*
 *
 *
 * This software has been made FREE by author for the interest of other developers. 
 *      I hope this will help you in coding faster and robust php code
 *            You can modify and redistribute it as you like.
 *              Your comments, suggestions and corrections 
 *                          will be highly 
 *                           APPRECIATED. 
 *                                      Author
 * @author :   Roshan Budhathoki (developer.roshan@gmail.com);
 * @URL    :   <http://www.roshanbudhathoki.com>
 *
 */

if (! Params::getParam ( 'action' )) {
	Params::setParam ( 'action', 'index' );
}

switch (Params::getParam ( 'action' )) {
	case 'index' :
		if (! Params::getParam ( 'category_id' )) {
			throw new Exception ( 'Category ID is not set' );
		}
		$cat = Model_Mapper_Categories::newInstance ()->getByID ( Params::getParam ( 'category_id' ) );
		$items = Model_Mapper_Items::newInstance ()->getByCategory ( Params::getParam ( 'category_id' ) );
		
		include cp_template_path () . 'items.php';
		break;
	
	case 'new' :
		break;
	case 'edit' :
		break;
	case 'edit_post' :
		break;
	case 'delete' :
		$where = '';
		$id = Params::getParam ( 'item_id' );
		$where = 'item_id=' . $id;
		$item = Model_Mapper_Items::newInstance ()->getByID ( $id );
		$cat = $item->getCategory ();
		$url = cp_url () . 'page=items&category_id=' . $cat->getCategory_id ();
		Model_Mapper_Items::newInstance ()->getDbTable ()->delete ( $where );
		redirect ( $url, true );
		break;
	case 'enable' :
		break;
	case 'disable' :
		break;

}


